<template>
  <div class="common-page alarm-page f-c">
    <div class="f-r a-c" style="margin-bottom: 33px">
      <div class="alarm-item f-r j-b">
        <div class="left">
          <div class="alarm-name">当前临期项目总数</div>
          <div class="alarm-value alarm-value1">
            <span>{{ countData.adventNum }}</span>
            <span class="alarm-unit">个</span>
          </div>
        </div>
        <div class="alarm-img alarm-img1">
          <img src="@/assets/alarm_icon1.png"/>
        </div>
      </div>

      <div class="alarm-item f-r j-b">
        <div class="left">
          <div class="alarm-name">当前超期项目总数</div>
          <div class="alarm-value alarm-value2">
            <span>{{ countData.overdueNum }}</span>
            <span class="alarm-unit">个</span>
          </div>
        </div>
        <div class="alarm-img alarm-img2">
          <img src="@/assets/alarm_icon2.png"/>
        </div>
      </div>
    </div>
    <div class="search-params f-r a-c j-b">
      <el-form inline label-width="110px">
        <el-form-item label="项目性质：">
          <el-select clearable v-model="searchParams.projectNature">
            <el-option v-for="item in options1" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="实施单位：">
          <el-input clearable v-model="searchParams.projectUnit" />
        </el-form-item>
        <el-form-item label="项目名称：">
          <el-input clearable v-model="searchParams.projectName" />
        </el-form-item>
        <el-form-item label="预警类型：">
          <el-select clearable v-model="searchParams.warningStatus">
            <el-option v-for="item in options2" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="f-r j-e">
      <el-form inline>
        <el-form-item>
          <el-button type="primary" round @click="onExport">导出</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box f-g">
      <el-table
          height="100%"
          v-loading="loading"
          stripe
          :data="tableData"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(255, 255, 255, 0.8)"
          @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <!--        <el-table-column label="预警阶段" width="250px" prop="step">-->
        <!--          <template slot-scope="scope">-->
        <!--            <div :class="['tag', 'tag' + scope.row.warningStatus ]">-->
        <!--              {{ scope.row.warningStage }}-->
        <!--            </div>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column label="操作" fixed="right" width="100px">
          <template slot-scope="scope">
            <el-button type="text" @click="onDelete(scope.row)">取消预警</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
          background
          :current-page="pageNo"
          :page-sizes="pageSizes"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalSize"
          @size-change="changePageSize"
          @current-change="changePageNo"
      />
    </div>

  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http_alarm } from '@/api'
import { exportFile } from '@/utils/request'
export default {
  name: 'Index',
  mixins: [crud],
  data() {
    return {
      request: http_alarm,
      dialogVisible: false,
      searchParams: {
        'projectName': null,
        'projectNature': null,
        'projectUnit': null,
        'warningStatus': null
      },
      options1: [],
      options2: [
        { value: 0, name: '正常' },
        { value: 1, name: '临期（黄色预警）' },
        { value: 2, name: '超期（红色预警）' }
      ],
      stageMap: {
        1: '项目立项阶段',
        2: '规划许可阶段',
        3: '施工许可阶段',
        4: '竣工验收阶段'
      },
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'projectType', label: '项目类型' },
        { prop: 'projectNature', label: '项目性质' },
        { prop: 'ageLimit', label: '建设起止年限' },
        { prop: 'totalAmount', label: '项目总投资(单位：万元)' },
        { prop: 'projectUnit', label: '实施单位' },
        { prop: 'eventName', label: '事项' },
        { prop: 'stageName', label: '事项阶段' },
        { prop: 'warningStatusName', label: '预警状态' },
      ],
      tableData: [
      ],
      countData: {}
    }
  },
  created() {
    http_alarm.count().then(res => {
      this.countData = res.data
    })
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.stageName = this.stageMap[el.stage]
        el.warningStatusName = this.options2.find(i => i.value === el.warningStatus)?.name
      })
    },
    onAdd() {
      this.dialogVisible = true
    },
    onExport() {
      exportFile('exportData/downloadWarning')
    },
    onDelete(rowItem = null) {
      this.$confirm('确认取消？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            this.request.delete(rowItem[this.deleteKey]).then(res => {
              this.onSearch()
            })
          })
          .catch(() => {

          })
    },
  }
}
</script>

<style lang="scss" scoped>
.alarm-page {
  .alarm-item {
    margin-right: 41px;
    width: 262px;
    height: 109px;
    background: #FFFFFF;
    box-shadow: 6px 6px 54px 1px rgba(0,0,0,0.05);
    border-radius: 14px 14px 14px 14px;
    opacity: 1;
    padding: 18px 16px;
    .alarm-img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      overflow: hidden;
      .el-image {
        width: 100%;
        height: 100%;
      }
    }
    .alarm-img1 {
      background-color: rgba(255, 218, 155, .21);
    }
    .alarm-img2 {
      background-color: rgba(255, 128, 128, .21);
    }
    .alarm-name {
      height: 16px;
      line-height: 16px;
      font-size: 16px;
      font-family: Source Han Sans CN-Regular, Source Han Sans CN;
      font-weight: 400;
      color: #202224;
      margin-bottom: 20px;
    }
    .alarm-value {
      font-size: 36px;
      line-height: 36px;
      font-family: Source Han Sans CN-Bold, Source Han Sans CN;
      font-weight: bold;
      color: #FEA917;
      .alarm-unit {
        font-size: 16px;
      }
    }
    .alarm-value1 {
      color: #FEA917;
    }
    .alarm-value2 {
      color: #D81E06;
    }
  }
  .tag {
    width: 223px;
    height: 56px;
    font-size: 12px;
    line-height: 16px;
    padding: 12px;
    border-radius: 12px;
  }
  .tag0 {
    background: #F1F5FF;
    border: 1px solid #4880FF;
    color: #4880FF;
  }
  .tag1 {
    background: #fceed7;
    border: 1px solid #FEA917;
    color: #FEA917;
  }
  .tag2 {
    border: 1px solid #F23232;
    background: #FFDBDB;
    color: #F51111;
  }
}
</style>
